﻿package
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.net.*;
  	import script.net.SocketRequestEvent;
	import main;
	import User;
	
	public class gameIntro extends MovieClip
	{
		private static var userName:String = "SomeUser";
		private var myURL:String = "http://chodaidi.ikoaguild.com";
		
		//Server Socket
		public var ourUserIDInput:String;
		public var ourGameIDInput:String;
		protected var ourAddressInput:String;
		protected var ourPortInput:String;
		protected var ourStatusDisplay:TextField;
		protected var myUser:User;
		private var ourConnectButton:Button;
		
		public function gameIntro()
		{
			userName_txt.text = String(userName);
			//init();
		}
		
		public function init():void
		{
			//Server Socket
			//ourAddressInput = "72.253.184.120"; //zn's IP
			ourAddressInput = "72.234.29.84"; //jur's IP
			ourPortInput = "8162";
			ourGameIDInput = "1";
			ourConnectButton = this["play_btn"];
			ourStatusDisplay = this["status_txt"];
			
			
			if(main.loginUser != null)
			{
				myUser = main.loginUser;
				userName_txt.text = myUser.userName;
			}
			else
			{
				userName_txt.text = "Sigh";
			}
			ourConnectButton.buttonMode = true;
			ourConnectButton.addEventListener(MouseEvent.CLICK, connectToServer);
		}
		
		protected function connectToServer(myEvent:MouseEvent):void
		{
			dispatchEvent(new SocketRequestEvent(SocketRequestEvent.CONNECT, 1, {address: ourAddressInput, port: ourPortInput}));
		}

		public function changeStatus(newStatus:String):void
		{
			ourStatusDisplay.text = newStatus;
		}
	}
}